package com.gogo.mall.wxpay;


import com.gogo.mall.result.ResponseData;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.protocol.ResponseDate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
public class Test {

    @GetMapping("sessiontest")
    public ResponseData testSession(HttpServletRequest request, HttpServletResponse response){

        HttpSession session = request.getSession();
        session.setAttribute("name","死神的世界");
        String sessionId = session.getId();
        Object name = session.getAttribute("name");
        HashMap<String, String> map = new HashMap<>();
        map.put("sessionId",sessionId);
        map.put("name", (String) name);

//
        Cookie[] cookies = request.getCookies();


        for (Cookie cookie : cookies) {
            System.out.println(cookie.getValue());
        }

        Cookie cookie = new Cookie("msg","好的好的" );

//        cookie.setValue("sddsf");
        cookie.setValue("hahaha");
        System.out.println(cookie.getValue());
        cookie.setMaxAge(120);
        response.addCookie(cookie);
        return new ResponseData(map);
    }


}
